#include "../common/message.hpp"
#include "../common/net.hpp"

void onMessage(const rpc::BaseConnection::ptr& conn,rpc::BaseMessage::ptr &msg)
{
    std::string body = msg->serialize();
    std::cout << body << std::endl;
    auto rpc_rsp = rpc::MessageFactory::create<rpc::RpcResponse>();
    rpc_rsp->setid("123");
    rpc_rsp->setmtype(rpc::Mtype::RSP_RPC);
    rpc_rsp->setRcode(rpc::Rcode::RCODE_OK);
    rpc_rsp->setResult(33);
    std::cout << "构建响应给客户端" << std::endl;
    conn->send(rpc_rsp);
}
int main()
{
    auto server = rpc::ServerFactory::create(9090);
    server->setMessageCallback(onMessage);
    server->start();
    return 0;
}